package com.anXin.schedule.feign;


import com.anXin.apis.schedule.IScheduleClient;
import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.schedule.dtos.Task;
import com.anXin.schedule.service.TaskService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
public class ScheduleClient implements IScheduleClient {

    @Resource
    private TaskService taskService;

    /**
     * 添加任务
     * @param task   任务对象
     * @return       任务id
     */
    @PostMapping("/api/v1/task/add")
    public ResponseResult addTask(@RequestBody Task task){
        return ResponseResult.okResult(taskService.addTask(task));
    }

    /**
     * 取消任务
     * @param taskId
     * @return
     */
    @GetMapping("/api/v1/task/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") Long taskId){
        return ResponseResult.okResult(taskService.cancelTask(taskId));
    }

    /**
     * 按照类型和优先级拉取任务
     * @param type
     * @param priority
     * @return
     */
    @GetMapping("/api/v1/task/{type}/{priority}")
    public ResponseResult poll(@PathVariable("type")int type, @PathVariable("priority")int priority){
        return ResponseResult.okResult(taskService.poll(type,priority));
    }
}
